home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / mipsABI / examples / after / dirent.c next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  624 b   |  33 lines

  1. /*
  2.  * illustrates use of directory routines
  3.  *
  4.  * If _ABI_SOURCE defined, include <dirent.h> instead of <sys/dir.h>
  5.  * and redefine the name of the directory struct
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <sys/types.h>
  10. #ifdef _ABI_SOURCE
  11. #define dirent direct
  12. #include <dirent.h>
  13. #else /* _ABI_SOURCE */
  14. #include <sys/dir.h>
  15. #endif /* _ABI_SOURCE */
  16.  
  17. main ()
  18. {
  19.     DIR *dp;
  20.     struct direct *dep;
  21.  
  22.     if ((dp = opendir (".")) == NULL)
  23.     {
  24.         fprintf (stderr, "cannot open current directory for reading\n");
  25.         exit (1);
  26.     }
  27.  
  28.     while ((dep = readdir (dp)) != NULL)
  29.         (void) printf ("%s\n", dep->d_name);
  30.     closedir (dp);
  31.     return (0);
  32. }
  33.